package com.smf.lsc.global.id.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.smf.lsc.global.id.GlobalId;
import com.smf.lsc.global.id.RedisGlobalIdImpl;
import com.smf.lsc.global.id.SnowflakGlobalIdImpl;

/**
 * 全局id配置
 * @author ln
 *
 */
@Configuration
@ComponentScan(basePackages = { "com.smf.lsc.*" })
public class GlobalIdConfig {

	@Bean
	@ConditionalOnMissingBean(GlobalId.class)
	@ConditionalOnProperty(name = { "global.id.type" }, havingValue = "redis")
	GlobalId redisGolobalIdProxy() {
		return new RedisGlobalIdImpl();
	}

	@Bean
	@ConditionalOnMissingBean(GlobalId.class)
	@ConditionalOnProperty(name = { "global.id.typ" }, havingValue = "snowflak", matchIfMissing = true)
	GlobalId snowflakGolobalIdProxy() {
		return new SnowflakGlobalIdImpl();
	}
}
